﻿using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using System.Web.Security;

namespace SampleWebsite.Workflow
{
	public sealed partial class LoginWorkflow: SequentialWorkflowActivity
	{
		public LoginWorkflow()
		{
			InitializeComponent();
		}

        private string username;

        /// <summary>
        /// Gets or sets the username.
        /// </summary>
        /// <value>The username.</value>
        public string Username
        {
            get { return username; }
            set { username = value; }
        }

        private string password;

        /// <summary>
        /// Gets or sets the password.
        /// </summary>
        /// <value>The password.</value>
        public string Password
        {
            get { return password; }
            set { password = value; }
        }

        private string returnUrl;

        public string ReturnUrl
        {
            get { return returnUrl; }
            set { returnUrl = value; }
        }
	
	
	    private bool isValidUser;

        private void ValidateUser_ExecuteCode(object sender, EventArgs e)
        {
            isValidUser = Membership.ValidateUser(username, password);
        }

        private void AuthenticateUser_ExecuteCode(object sender, EventArgs e)
        {
            FormsAuthentication.SetAuthCookie(username, false);
        }

        private void ReturnToLogin_ExecuteCode(object sender, EventArgs e)
        {
            FormsAuthentication.RedirectToLoginPage("error=Invalid+user");
        }
	}

}
